from apps.task.settings import config
from flask_apscheduler import APScheduler

if config.SERVER_ENV != 'dev':
    from gevent import monkey

    monkey.patch_all()
else:
    pass

from apps.task.views.citask import ciTask
from library.api.tFlask import tflask


def create_app():
    app = tflask(config)
    register_blueprints(app)
    scheduler = APScheduler()  # 实例化APScheduler
    scheduler.init_app(app)  # 把任务列表载入实例flask
    scheduler.start()  # 启动任务计划
    return app


def register_blueprints(app):
    app.register_blueprint(ciTask, url_prefix="/v1/ci/task")


if __name__ == '__main__':
    create_app().run(port=config.PORT)
